import os
from pathlib import Path
filepath = '/Users/ayuliao/Downloads/Python编程快速上手-让繁琐工作自动化.pdf'
def get_filesize(filepath):
    # #  获取文件大小，单位Bytes
    # fsize = os.path.getsize(filepath)
    fsize = Path(filepath).stat().st_size
    # Bytes转MB
    fsize = fsize / float(1000 * 1000)
    return round(fsize, 4)

fsize = get_filesize(filepath)
print(f'file size: {fsize}MB')

import time
def get_time(timestamp):
    '''格式化时间戳'''
    t = time.localtime(timestamp)
    return time.strftime('%Y-%m-%d %H:%M:%S', t)

filepath = '测试.txt'
# 文件创建时间
# ctime = os.path.getctime(filepath)
ctime = Path(filepath).stat().st_ctime
ctime = get_time(ctime)
# 文件修改时间
# mtime = os.path.getmtime(filepath)
mtime = Path(filepath).stat().st_mtime
mtime = get_time(mtime)
print(f'create time: {ctime}, modify time: {mtime}')
